'use client';

import DOMPurify from 'dompurify';

/** 净化 HTML 并防止 XSS 攻击(客户端)
 * https://www.npmjs.com/package/dompurify
 */
export const sanitize = (domString: string) => {
  try {
    return DOMPurify.sanitize(domString, { USE_PROFILES: { html: true } });
  } catch {
    return '<div></div>';
  }
};
